package com.tledu.ssm01.service;

import com.tledu.ssm01.core.exception.CustomException;
import com.tledu.ssm01.mapper.UserMapper;
import com.tledu.ssm01.model.User;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Antg
 * @date 2021/8/12  18:40
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService{
    private UserMapper userMapper;
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User login(String username, String password) {
        User user = userMapper.findByUserName(username);
        if(user==null){
            throw new CustomException("用户不存在",500);
        }
        if(!password.equals(user.getPassword())){
            throw new CustomException("密码错误",501);
        }
        //登录成功
        return user;
    }

    @Override
    public int editUser(User user) {
        return userMapper.editUser(user);
    }

    @Override
    public int editHeadPic(Integer id, String headPic) {
        return userMapper.editHeadPic(id, headPic);
    }

    @Override
    public User findByUserName(String username) {
        return userMapper.findByUserName(username);
    }
}
